/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.metadata.staticschemas;

import java.io.InputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class StaticJenaRDFS {
	  /** <p>The RDF model that holds the vocabulary terms</p> */
    private static Model m_model = ModelFactory.createDefaultModel();
    
    /** <p>The namespace of the vocabulary as a string</p> */
    public static final String NS = "http://www.w3.org/2000/01/rdf-schema#";
    
    /** <p>The namespace of the vocabulary as a string</p>
     *  @see #NS */
    public static String getURI() {return NS;}
    
    /** <p>The namespace of the vocabulary as a resource</p> */
    public static final Resource NAMESPACE = m_model.createResource( NS );
    
    /** <p>A description of the subject resource.</p> */
    public static final Property comment = m_model.createProperty( "http://www.w3.org/2000/01/rdf-schema#comment" );
    
    /** <p>A domain of the subject property.</p> */
    public static final Property domain = m_model.createProperty( "http://www.w3.org/2000/01/rdf-schema#domain" );
    
    /** <p>The defininition of the subject resource.</p> */
    public static final Property isDefinedBy = m_model.createProperty( "http://www.w3.org/2000/01/rdf-schema#isDefinedBy" );
    
    /** <p>A human-readable name for the subject.</p> */
    public static final Property label = m_model.createProperty( "http://www.w3.org/2000/01/rdf-schema#label" );
    
    /** <p>A member of the subject resource.</p> */
    public static final Property member = m_model.createProperty( "http://www.w3.org/2000/01/rdf-schema#member" );
    
    /** <p>A range of the subject property.</p> */
    public static final Property range = m_model.createProperty( "http://www.w3.org/2000/01/rdf-schema#range" );
    
    /** <p>Further information about the subject resource.</p> */
    public static final Property seeAlso = m_model.createProperty( "http://www.w3.org/2000/01/rdf-schema#seeAlso" );
    
    /** <p>The subject is a subclass of a class.</p> */
    public static final Property subClassOf = m_model.createProperty( "http://www.w3.org/2000/01/rdf-schema#subClassOf" );
    
    /** <p>The subject is a subproperty of a property.</p> */
    public static final Property subPropertyOf = m_model.createProperty( "http://www.w3.org/2000/01/rdf-schema#subPropertyOf" );
    
    /** <p>The class of classes.</p> */
    public static final Resource Class = m_model.createResource( "http://www.w3.org/2000/01/rdf-schema#Class" );
    
    /** <p>The class of RDF containers.</p> */
    public static final Resource Container = m_model.createResource( "http://www.w3.org/2000/01/rdf-schema#Container" );
    
    /** <p>The class of container membership properties, rdf:_1, rdf:_2, ..., all of 
     *  which are sub-properties of 'member'.</p>
     */
    public static final Resource ContainerMembershipProperty = m_model.createResource( "http://www.w3.org/2000/01/rdf-schema#ContainerMembershipProperty" );
    
    /** <p>The class of RDF datatypes.</p> */
    public static final Resource Datatype = m_model.createResource( "http://www.w3.org/2000/01/rdf-schema#Datatype" );
    
    /** <p>The class of literal values, eg. textual strings and integers.</p> */
    public static final Resource Literal = m_model.createResource( "http://www.w3.org/2000/01/rdf-schema#Literal" );
    
    /** <p>The class resource, everything.</p> */
    public static final Resource Resource = m_model.createResource( "http://www.w3.org/2000/01/rdf-schema#Resource" );
    
    public static Model getModel()
    {
	ClassLoader classLoader = Thread.currentThread()
	.getContextClassLoader();
	InputStream is;
	is = classLoader.getResourceAsStream("rdf-schema.rdf");

    	Model myModel = ModelFactory.createDefaultModel();
    	
    	try {
    	    myModel.read(is, "");
    	    return myModel;
    	}catch (Exception ex) {
    	    return myModel;
    	}      
    }
    
    public static boolean containsProperty(String localName)
    {
    	if (StaticJenaRDFS.comment.getLocalName().equals(localName) ||
    			StaticJenaRDFS.domain.getLocalName().equals(localName) ||
    			StaticJenaRDFS.isDefinedBy.getLocalName().equals(localName) ||
    			StaticJenaRDFS.label.getLocalName().equals(localName) ||
    			StaticJenaRDFS.member.getLocalName().equals(localName) ||
    			StaticJenaRDFS.range.getLocalName().equals(localName) ||
    			StaticJenaRDFS.seeAlso.getLocalName().equals(localName) ||
    			StaticJenaRDFS.subClassOf.getLocalName().equals(localName) ||
    			StaticJenaRDFS.subPropertyOf.getLocalName().equals(localName))
    		return true;
    	else return false;
    }
    
    public static boolean containsResource(String localName)
    {
    	if (StaticJenaRDFS.Class.getLocalName().equals(localName) ||
    			StaticJenaRDFS.Container.getLocalName().equals(localName) ||
    			StaticJenaRDFS.ContainerMembershipProperty.getLocalName().equals(localName) ||
    			StaticJenaRDFS.Datatype.getLocalName().equals(localName) ||
    			StaticJenaRDFS.Literal.getLocalName().equals(localName) ||
    			StaticJenaRDFS.Resource.getLocalName().equals(localName))
    		return true;
    	else return false;
    }
    
}
